package cn.sjxy.doctorms.controller;

import cn.sjxy.doctorms.domain.Doctor;
import cn.sjxy.doctorms.domain.Result;
import cn.sjxy.doctorms.mapper.DepartmentMapper;
import cn.sjxy.doctorms.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/doc")
@Validated// 使用Validated注解，启用参数校验功能，对应下面的@Pattern注解
public class DoctorController {
    @Autowired
    private DoctorService ds;
    @Autowired
    private DepartmentMapper dm;

    // 查询所有医生信息（含部门项加载）
    @GetMapping("alldoc")
    public Result<List<Doctor>> list(){
        List<Doctor> cs = ds.findAllDoctors();
        return Result.success(cs);
    }

    //查询单个医生信息
    @GetMapping("/{doctorId}")
    public Result<Doctor> get(@PathVariable Integer doctorId) {
        Doctor doctor = ds.getDocBySubStep(doctorId);
        return Result.success(doctor);
    }

    // 修改医生信息
    @PutMapping("/update")
    public Result update(@RequestBody @Validated Doctor doctor) {
        ds.updateDoctor(doctor);
        return Result.success();
    }

    // 添加医生信息
    @PostMapping("/add")
    public Result add(@RequestBody @Validated Doctor doctor) {
        ds.insertDoctor(doctor);
        return Result.success();
    }

    // 删除医生信息
    @DeleteMapping("/delete")
    public Result delete(@RequestParam @Validated Integer doctorId) {
        ds.deleteDoctor(doctorId);
        return Result.success();
    }

}
